package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.dto.OrgDto;
import com.hualude.roadsign.service.OrgService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;


/**
 * Created by xu-jiaHui on 2017/2/25.
 */
@Controller
@RequestMapping("/rds_org")
public class OrgController {

    @Resource
    private OrgService orgService;

    @RequestMapping(value = "/getOrg4DT")
    @ResponseBody
    public DTResponseDto getOrg4DT(DTRequestDto dtRequestDto, Integer actorId, Integer orgId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = orgService.getOrg4DT(dtRequestDto, actorId, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/addOrg")
    @ResponseBody
    public JsonMsgDto addOrg(OrgDto orgDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(orgService.addOrg(orgDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/updateOrgById")
    @ResponseBody
    public JsonMsgDto updateOrgById(OrgDto orgDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(orgService.updateOrgById(orgDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deactivateOrgByIds")
    @ResponseBody
    public JsonMsgDto deactivateOrgByIds(String orgIds, Integer orgState) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(orgService.deactivateOrgByIds(orgIds, orgState));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getMainOrgNameAndId")
    @ResponseBody
    public JsonMsgDto getMainOrgNameAndId(Integer orgId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(orgService.getMainOrgNameAndId(orgId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getOrgNameAndId")
    @ResponseBody
    public JsonMsgDto getOrgNameAndId() {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(orgService.getOrgNameAndId());
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }


    @RequestMapping(value = "/getOrgFatherNameByOrgId")
    @ResponseBody
    public JsonMsgDto getOrgFatherNameByOrgId(Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(orgService.getOrgFatherNameByOrgId(orgId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getCandidateMainOrgIdAndNameByOrgId")
    @ResponseBody
    public DTResponseDto getCandidateMainOrgIdAndNameByOrgId(DTRequestDto dtRequestDto, Integer orgId) throws Exception {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = orgService.getCandidateMainOrgIdAndNameByOrgId(dtRequestDto, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/getMainOrgIdAndNameByOrgId")
    @ResponseBody
    public DTResponseDto getMainOrgIdAndNameByOrgId(DTRequestDto dtRequestDto, Integer orgId) throws Exception {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = orgService.getMainOrgIdAndNameByOrgId(dtRequestDto, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/addMainOrg4OrgId")
    @ResponseBody
    public JsonMsgDto addMainOrg4OrgId(Integer orgId, Integer mainOrgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(orgService.addMainOrg4OrgId(orgId, mainOrgId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteMainOrgByIds")
    @ResponseBody
    public JsonMsgDto deleteMainOrgByIds(Integer orgId, Integer mainOrgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(orgService.deleteMainOrgByIds(orgId, mainOrgId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getOrgNameByOrgId")
    @ResponseBody
    public JsonMsgDto getOrgNameByOrgId(Integer orgId, Integer orgType) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(orgService.getOrgNameByOrgId(orgId, orgType));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getCountByOrgName")
    @ResponseBody
    public JsonMsgDto getCountByOrgName(String orgName) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(orgService.getCountByOrgName(orgName));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteOrgByOrgId")
    @ResponseBody
    public JsonMsgDto deleteOrgByOrgId(Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(orgService.deleteOrgByOrgId(orgId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/addMenu")
    @ResponseBody
    public JsonMsgDto addMenu(OrgDto orgDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(orgService.addMenu(orgDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getOrgMenu")
    @ResponseBody
    public JsonMsgDto getOrgMenu(Integer orgId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(orgService.getOrgMenu(orgId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }
}
